package com.example.udpDemo.socket.design.singleton;

import cn.hutool.core.util.RandomUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wangdachuan
 * @version 1.0
 * @date 2023/4/6 00:19
 **/
@Slf4j
public class SingletonTest {


    /**
     * 得到数据变化时间
     *
     * @param temperatureList 温度列表
     * @return {@link Integer}
     */
    public static Integer getDataChangeTimes(List<Float> temperatureList){
        Float tmpTemperature = null;
        Integer changeTimes = 0;
        for(Float temperature : temperatureList){
            if(null == tmpTemperature || !tmpTemperature.equals(temperature)){
                changeTimes++;
                tmpTemperature = temperature;
            }
        }
        return changeTimes;
    }

    public static void main(String[] args) {
//        Singleton01 singleton01 = Singleton01.getInstance();
//        Singleton01 singleton011 = new Singleton01();
//        log.info("判断结果：{}", singleton011 == singleton01);
        List<Float> temperatureList = new ArrayList<>();
        long start = System.currentTimeMillis();
        for (int i = 0; i < 87600; i++){
            temperatureList.add(RandomUtil.randomBigDecimal().floatValue());
        }
        System.out.println("温度数据：" + temperatureList.size());
        System.out.println("温度变化次数：" + getDataChangeTimes(temperatureList));
        System.out.println("温度变化计算耗时：" + (System.currentTimeMillis() - start));


    }
}
